import 'dart:async';

import 'package:flutter/material.dart';
import '../entity/mall_goods_entity.dart';
import '../entity/category_entity.dart';

///
/// 分类页子分类
///
class ChildCategoryModel with ChangeNotifier {
  ///子类别当前索引
  int _currentChildIndex = 0;
  int get currentChildIndex => _currentChildIndex;

  ///当前点击的子类
  CategoryBxmallsubdto _bxmallsubdto;
  CategoryBxmallsubdto get bxmallsubdto => _bxmallsubdto;

  ///子类别列表
  List<CategoryBxmallsubdto> _childCategory;
  List<CategoryBxmallsubdto> get childCategoryList => _childCategory;


  ///下拉刷新的
  StreamController<List<MallGoodsEntity>> _streamCtrl;
  StreamController<List<MallGoodsEntity>> get streamCtrl => _streamCtrl;

  ChildCategoryModel(){
    _childCategory=List();
    _streamCtrl=StreamController();
  }

  void setCurrentChildIndex(int index) {
    _currentChildIndex = index;
    notifyListeners();
  }

  void setChildCategory(CategoryBxmallsubdto childCategory) {
    _bxmallsubdto = childCategory;
    notifyListeners();
  }

  void setChildCategoryAndIndex(CategoryBxmallsubdto childCategory,int index){
    _bxmallsubdto = childCategory;
    _currentChildIndex = index;
    notifyListeners();
  }


  void setChildCategoryList(List<CategoryBxmallsubdto> newChildCategory) {
    _childCategory.clear();
    _childCategory.addAll(newChildCategory);

    ///添加名称为 全部 的分类
    if (_childCategory != null && _childCategory.isNotEmpty) {
      String mallCategoryId = newChildCategory[0].mallCategoryId;
      CategoryBxmallsubdto all =
      CategoryBxmallsubdto(mallSubName: "全部", mallCategoryId: mallCategoryId, mallSubId: "");
      _childCategory.insert(0, all);
    }
    notifyListeners();
  }
}


final ChildCategoryModel childCategoryModelDef=ChildCategoryModel();